package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    SettingManager settingManager;

    //查询通用设置
    @GetMapping("/users/settings")
    public ResponseEntity findSetting(){
        return settingManager.findSetting();
    }

    //设置陌生人问题
    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String,String> map){
        //1.获取用户输入的问题内容
        String content = map.get("content");

        //2.调用manager完成操作
        settingManager.setQuestion(content);
    }

    //设置通知
    @PostMapping("/users/notifications/setting")
    public void setNotification(@RequestBody Notification param){
        settingManager.setNotification(param);
    }

    //黑名单列表
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){
        return settingManager.findBlackListByPage(pageNum,pageSize);
    }

    //移除黑名单
    @DeleteMapping("/users/blacklist/{blackId}")
    public void deleteBlackList(@PathVariable Long blackId){
        settingManager.deleteBlackList(blackId);
    }
}
